/*
 * Copyright (c) 2015. For Intelligent Group.
 */

package com.intelligent.ispc.common.utils;

import java.security.SecureRandom;
import java.util.UUID;

/**
 * Identity tools.
 * <p>
 * Created by Peter.Li on 2015/10/9.
 */
public class Identities {

    private static SecureRandom random = new SecureRandom();

    /**
     * JDK-UUID, generate by Random number split with '-'.
     *
     * @return uuid.
     */
    public static String uuid() {
        return UUID.randomUUID().toString();
    }

    /**
     * JDK-UUID, generate by Random number with removed all '-'.
     *
     * @return uuid.
     */
    public static String uuid2() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    /**
     * Generate random lang with SecureRandom.
     *
     * @return random lang.
     */
    public static long randomLong() {
        return Math.abs(random.nextLong());
    }

    /**
     * Generate bytes base on Base62 encoding of SecureRandom.
     *
     * @param length random length.
     * @return random string with encoding by Base62.
     */
    public static String randomBase62(int length) {
        byte[] randomBytes = new byte[length];
        random.nextBytes(randomBytes);
        return Encodes.encodeBase62(randomBytes);
    }
}
